<template>
  <div class="box">
    <header class="header">
      <van-nav-bar
        title="修改信息"
        left-arrow
        @click-left="$router.go(-1)"
      ></van-nav-bar>
    </header>
    <div class="content">
      <van-field
        v-model="nickname"
        name="昵称"
        label="昵称"
<<<<<<< HEAD
        placeholder="昵称"
        clearable
=======
        clearable
        placeholder="昵称"
>>>>>>> 68b657acc83398406018ec9d69a526c64a82d2c8
      />
      <van-field
        v-model="email"
        name="邮箱"
        label="邮箱"
<<<<<<< HEAD
        placeholder="邮箱"
        clearable
=======
        clearable
        placeholder="邮箱"
>>>>>>> 68b657acc83398406018ec9d69a526c64a82d2c8
      />
      <van-field name="radio" label="性别">
        <template #input>
          <van-radio-group v-model="sex" direction="horizontal">
            <van-radio name="1">男</van-radio>
            <van-radio name="0">女</van-radio>
          </van-radio-group>
        </template>
      </van-field>
<<<<<<< HEAD
      <van-button block color="#f66" @click="updateInfo">提交</van-button>
=======
      <van-button block color="skyblue" @click="updateInfo">提交</van-button>
>>>>>>> 68b657acc83398406018ec9d69a526c64a82d2c8
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import { NavBar, Form, Field, RadioGroup, Radio, Button } from 'vant'
import { getuserinfo, updateinfo } from '@/api'
Vue.use(NavBar)
Vue.use(Form)
Vue.use(Field)
Vue.use(RadioGroup)
Vue.use(Radio)
Vue.use(Button)
export default {
  data () {
    return {
      nickname: '',
      email: '',
      sex: ''
    }
  },
  mounted () {
    getuserinfo({
      userid: localStorage.getItem('userid'),
      token: localStorage.getItem('token')
    }).then(res => {
      if (res.data.code === '10119') {
        // 未登录直接跳转到登录页面
        this.$router.push('/login')
      } else {
<<<<<<< HEAD
        // 已登陆，填写表单信息
=======
        // 已登录，填写表单信息
>>>>>>> 68b657acc83398406018ec9d69a526c64a82d2c8
        this.nickname = res.data.data.nickname
        this.email = res.data.data.email
        this.sex = res.data.data.sex
      }
    })
  },
  methods: {
    updateInfo () {
      // 提交至数据库
      updateinfo({
        userid: localStorage.getItem('userid'),
        token: localStorage.getItem('token'),
        nickname: this.nickname,
        email: this.email,
        sex: this.sex
      }).then((res) => {
        if (res.data.code === '10119') {
          // 未登录直接跳转到登录页面
          this.$router.push('/login')
        } else {
          this.$router.go(-1)
        }
      })
    }
  }
}
</script>
<<<<<<< HEAD
=======

<style lang="scss">
.btn {
   border-radius: 25px;
}
</style>
>>>>>>> 68b657acc83398406018ec9d69a526c64a82d2c8
